import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class LoadingDialog extends StatefulWidget {
  String text = '';
  LoadingDialog({super.key,this.text = "加载中..."});

  @override
  State<LoadingDialog> createState() => _LoadingDialogState();
}

class _LoadingDialogState extends State<LoadingDialog> with SingleTickerProviderStateMixin{

  late AnimationController _animationController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _animationController = AnimationController(vsync: this,duration: const Duration(seconds: 1));
    _animationController.forward();

  }
  @override
  Widget build(BuildContext context) {
    return Material(
      type: MaterialType.transparency,//透明类型
      child: Center(
        child: SizedBox(
          width: 100,
          height: 100,
          child: Container(
            decoration: const ShapeDecoration(
              color: Colors.black45,
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(8.0))
                )
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Center(
                  child: RotationTransition(
                    turns: _animationController..addStatusListener((status) {
                        if(status == AnimationStatus.completed) {
                          _animationController.reset();
                          _animationController.forward();
                        }
                      }),
                    child: Image.asset(
                      'assets/images/loading/common_loading.png',
                      height: 100.w,
                      width: 100.w,
                    )
                  ),
                ),
                Text(widget.text,style: const TextStyle(fontSize: 24,color: Colors.white),)
              ],
            ),
          ),
        ),
      ),
    );
  }
  @override
  void dispose() {
    // TODO: implement dispose
    _animationController.dispose();
    super.dispose();
  }
}
